<?php
foreach($chatmessage as $row){
?>
    <div class="wallpost" width="500">
        <div>
            <img src="<?php
            if($row['sender'] == $chatid['from']){
                echo $chatp['from'];
            } else {
                echo $chatp['to'];
            }
            ;?>" height="70" width="70"/>
        </div>
            <div class="random_text">
            <?php
            echo $row['sender'];
            ?>
            </div>
            <div class="chat-date">
            <?php
            echo $row['date'];
            ?>
            </div>
            <div class="chat-msg">
            <?php
            echo $row['msg'];
            ?>
            </div>
            <br />
    </div>
    <?php
}
?>